"""
@name : error_code
@author : FengZT_19
@projectname: myflask
"""
from werkzeug.exceptions import HTTPException

class APIException(HTTPException):
    print("this is API")
    code = 500  # http状态码
    message = "opps!"  # 状态描述信息
    status_code = 9999  # 程序状态码

    def __init__(self, message=None, code=None, status_code = None):
        if message:
            self.message = message
        if code:
            self.code = code
        if status_code:
            self.status_code = status_code
        super(APIException, self).__init__()

    def get_body(
        self,
        environ=None,
        scope=None,
    ) -> str:
        body = dict(
            message = self.message,
            status_code = self.status_code
        )
        import json
        content = json.dumps(body)
        return content

    def get_headers(
        self,
        environ = None,
        scope = None,
    ) :
        return [('content-Type', 'application/json')]

class APIAuthorizedException(APIException):
    message = "API授权认证失败"
    status_code = 10002
    code = 401

class FormValidateException(APIException):
    message = "表单验证失败"
    status_code = 10003

class TokenTimeoutException(APIException):
    message = "token过期，验证失败"
    status_code = 10006
    code = 401

class TokenFailException(APIException):
    message = "token不合法，验证失败"
    status_code = 10005
    code = 401

class MonitorException(APIException):
    message = "monitor不存在"
    status_code = 10006
    code = 404

class UserException(APIException):
    message = "user不存在"
    status_code = 10007
    code = 404

class SexException(APIException):
    message = "请输入正确的性别（F or M）"
    status_code = 10008
    code = 401

class PARAMException(APIException):
    message = "参数错误"
    status_code = 10009
    code = 404

class ArticleException(APIException):
    message = "article不存在"
    status_code = 100010
    code = 404


class BookCategoriesException(APIException):
    message = "Bookcategories不存在"
    status_code = 100011
    code = 404